package com.fyl.log;

import com.fyl.log.anno.EnableAsyncLog;
import com.fyl.log.service.AsyncLogService;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

public class LogServiceRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableAsyncLog.class.getName()));
        assert annoAttrs != null;
        Class<?> value = annoAttrs.getClass("value");
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(value);
        registry.registerBeanDefinition(AsyncLogService.class.getSimpleName(), builder.getBeanDefinition());
    }
}
